package com.mianshi;

import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public class zoom1 {
    public static void main(String[] args) {

    }

    public boolean isValisd(String str){
        int n = str.length();
        if(n % 2 == 0){
            return false;
        }
        Map<Character,Character> map = new HashMap<>();
        map.put('>','<');
        map.put(')','(');
        map.put(']','[');
        map.put('}','{');
        Deque<Character> stack = new LinkedList<>();
        for(int i = 0; i < n; i++){
            char c = str.charAt(i);
            if(map.containsKey(c)){
                if(stack.isEmpty() || stack.peek() != map.get(c)){
                    return false;
                }
                stack.pop();
            }else{
                stack.push(c);
            }
        }
        return stack.isEmpty();
    }
}
